// 引入左侧菜单栏的处理函数
// const { log } = require('util')
const db = require('../db/index')
exports.getMenu = (req, res) => {
    // res.ResData('sda')
    var sql = "select * from sp_permission,sp_permission_api where sp_permission.ps_id=sp_permission_api.ps_id"
    db.query(sql, (err, result) => {
        if (err) return res.ResData('获取菜单栏')
            // res.ResData(result)
            // console.log(result);
            // 获取一级菜单
        var rootPermissionResult = {}
        for (index in result) {
            permission = result[index];
            if (permission.ps_level == 0) {
                rootPermissionResult[permission.ps_id] = {
                    'id': permission.ps_id,
                    'authName': permission.ps_name,
                    'path': permission.ps_api_path,
                    'children': [],

                }
            }
        }
        // console.log(rootPermissionResult);
        for (index in result) {
            permission = result[index];
            if (permission.ps_level == 1) {
                parentPermissionResult = rootPermissionResult[permission.ps_pid];
                if (parentPermissionResult) {
                    parentPermissionResult.children.push({
                        'id': permission.ps_id,
                        'authName': permission.ps_name,
                        'path': permission.ps_api_path,
                    })
                }
            }
        }
        // console.log(rootPermissionResult);
        res.ResData("获取左侧菜单栏", 200, rootPermissionResult)

    })
}